import apis from "../../http/apis/apis"
export default {
    //避免命名冲突
    namespaced: true,
    state: {
        tableData1: [
        ],
        currentPage1: 1,
        pageSize1: 5,
        total1: 0,
        pages1: 0,
    
    //查询车辆
    formInline: {
        seatchtype: "",
        seatchval: "",
      }, 
    tableData: {
         parkings:[],
         pageSize:2,
         currentPage:1,
         total:0,
         state:""
    }

    },
    mutations: {
        auditparkings(state, data) {
            state.tableData1= data.data2,
                state.total1 = data.allPages
        },
        //改变每页显示条数
        changePageSize(state, pageSize) {
            state.pageSize1 = pageSize
        },
        //改变当前页
        changecurrentPage(state, currentPage) {
            state.currentPage1 = currentPage
        },
        //获取车辆
        getparks(state,val){
            state.tableData.parkings=val.ingetparks
            state.tableData.total=val.total
        }, 
    },
    actions: {
        async addParkings(context, newParkings) {
            const { data } = await apis.parkings.addParkings(newParkings)
            if (data.status) {
                return data
            } else {
                alert("添加失败")
            }
        },
        //获取车辆
        async getparkings(context,lessorsId){
         const {data} = await apis.parkings.getparkings({
            lessorsId:lessorsId,
            seatchtype:context.state.formInline.seatchtype,
            seatchval:context.state.formInline.seatchval,
            pageSize:context.state.tableData.pageSize,
            currentPage:context.state.tableData.currentPage,
            state:context.state.tableData.state
         });
         if(data.status){
            context.commit("getparks",data.getparks)
        }
    },
        //审核车位渲染列表
        async auditParkings(context, input) {
            const data = await apis.parkings.auditParkings({
                searchType: input.input1,
                searchValue: input.input2,
                currentPage: context.state.currentPage1,
                pageSize: context.state.pageSize1
            });
            if (data.status) {
                console.log("111",data);
                context.commit('auditparkings', data.data)
            }
        },
        async getState(context, a) {
            const { data } = await apis.parkings.getState({
                _id: a,
                state: 2
            });
            return data
        }
   }
}
